package org.example.mapper;

import org.example.model.Experiment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ExperimentMapper {
    @Insert("INSERT INTO experiment (name, course_name, description, due_date, create_time, update_time) VALUES (#{name}, #{courseName}, #{description}, #{dueDate}, now(), now())")
    int insertExperiment(Experiment experiment);

    @Update("UPDATE experiment SET name = #{name}, course_name = #{courseName}, description = #{description}, due_date = #{dueDate}, update_time = now() WHERE id = #{id}")
    int updateExperiment(Experiment experiment);

    @Delete("DELETE FROM experiment WHERE id = #{id}")
    int deleteExperiment(Long id);

    @Select("SELECT * FROM experiment WHERE id = #{id}")
    Experiment getExperimentById(Long id);

    @Select("SELECT * FROM experiment")
    List<Experiment> getAllExperiments();

    @Select("SELECT * FROM experiment WHERE course_name = #{courseName}")
    List<Experiment> getExperimentsByCourse(String courseName);
}
